HW 2
Question 1
Explain the following terms:
- Race condition: it occurs when two or more threads can access shared data and they try to change it at the same time.
- Shared memory programming model: in this model, tasks share a common address space, which they read and write in an asynchronous manner.
- Asynchronous execution: Order of execution of instructions depends on input data, OS scheduling algorithm, speed of the processors, and speed of communication network.
- Atomic Instruction: For example, when accessing or mutating a property is atomic, it means that only one read or write operation can be performed at a time.
- Correct parallel program: For all data inputs, for all execution sequences, correct output is produced
Question 2
2.1
First of all, the execution time without parallelization is .
We have multiplications in total, and it's fair to divide them evenly among threads. Each thread is in charge of multiplying every element assigned and if more than one element is assigned, the thread also needs to sum up the results from multiplications. After all, each thread produces a value that is to be summed up to get the final result.
In each thread, there will be elements assigned meaning there will be multiplications and additions (Simplified to ). Overall, it does computations.
This is a scalable result because
2.2
Question 3
3.1
3.2
Question 4
4.1
s(i) and At_least_one_vertex_has_update are shared.